package cn.stu.lqj.demo.serviceImpl;

import cn.stu.lqj.demo.mapper.DeptMapper;
import cn.stu.lqj.demo.mapper.EmpMapper;
import cn.stu.lqj.demo.pojo.Dept;
import cn.stu.lqj.demo.pojo.Emp;
import cn.stu.lqj.demo.service.EmpService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.ui.Model;

import java.util.ArrayList;
import java.util.List;

@Service
public class EmpServiceImpl implements EmpService {
    @Autowired(required = false)
    private EmpMapper empMapper;


    @Override
    public String findAllEmp(Model model) {
        QueryWrapper<Emp> queryWrapper = new QueryWrapper<>();
        List<Emp> list = empMapper.selectList(queryWrapper);
        List<Emp> list1 = new ArrayList<>();
        for (Emp emp : list) {
            if (emp.getIsdelete().equals("0"))
                list1.add(emp);
        }

//        System.out.println(list1+"-----------1111---");
        model.addAttribute("empList", list1);
        return "empList";//跳转到门店列表


    }

    @Override
    public String findAllHistoriaEmp(Model model) {
        QueryWrapper<Emp> queryWrapper = new QueryWrapper<>();
        List<Emp> list = empMapper.selectList(queryWrapper);
        List<Emp> list1 = new ArrayList<>();
        for (Emp emp : list) {
            if (emp.getIsdelete().equals("1"))
                list1.add(emp);
        }

//        System.out.println(list1+"-----------1111---");
        model.addAttribute("empList1", list1);
        return "empList_Historia";//跳转到门店列表
    }

    public String deleteById(Integer id) {
        Emp emp = empMapper.selectById(id);
//        System.out.println(emp);
        emp.setIsdelete("1");
//        System.out.println(emp);
        empMapper.updateById(emp);
        return "redirect:/emp/findAllEmps";
    }

    @Override
    public String toUpdateByEmpId(Integer id, Model model) {
        Emp emp = empMapper.selectById(id);
        model.addAttribute("emp", emp);
        return "updateEmp";
    }

    @Override
    public String updateByEmpId(Emp emp) {
//        QueryWrapper<Emp> queryWrapper=new QueryWrapper<>();
        System.out.println(emp);
        empMapper.updateById(emp);
        return "redirect:/emp/findAllEmps";
    }

//    @Override
//    public String findDetailById(Integer empId, Model model) {
//        Dept dept = deptMapper.selectById(empId);
//        System.out.println("dept"+dept);
//        model.addAttribute("dept", dept);
//        return "findDetailById";
//    }

}
